home *** CD-ROM | disk | FTP | other *** search
- class PlayPump extends GameObject
- {
- var hit;
- var addChildInd;
- var onDragOut;
- var onDragOver;
- var queue;
- var exit;
- var spinnerGuide;
- var leaveLeft;
- var leaveRight;
- var goToSlotGuide;
- var slots;
- var kidsInteractingWithPump;
- var spinner;
- var engine;
- var shadow;
- var _r = 0;
- static var OPTIMUM_SPEED = 16;
- static var OPTIMUM_KIDS = 1;
- static var MAX_KIDS = 5;
- static var SLOT_ANG = 1 / PlayPump.MAX_KIDS;
- static var LITRES_PER_ROTATION = 0.5;
- static var KID_LEAVE_POINT = 0.51;
- static var MIN_TURN_SPEED = 0;
- static var MAX_KIDS_INTERACTING_WITH_PUMP = 7;
- function PlayPump()
- {
- super();
- this.hitArea = this.hit;
- this.hit._visible = false;
- this.addChildInd._visible = false;
- this.onDragOut = this.onRollOut;
- this.onDragOver = this.onRollOver;
- }
- function init(e, q, p)
- {
- super.init(e);
- this.queue = q;
- this.exit = p;
- this.spinnerGuide.init(e);
- this.exit.init(e);
- this.leaveLeft.init(e);
- this.leaveRight.init(e);
- this.goToSlotGuide.init(e);
- this.slots = [];
- this.kidsInteractingWithPump = 0;
- this.swapDepths(this.getTargetDepth());
- }
- function onRollOver()
- {
- this.addChildInd._visible = true;
- this.spinner.filters = [GameObject.GLOW_FILTER];
- }
- function onRollOut()
- {
- this.addChildInd._visible = false;
- this.spinner.filters = [];
- }
- function onRelease()
- {
- if(this.engine.labourPool.length)
- {
- if(this.kidsInteractingWithPump < PlayPump.MAX_KIDS_INTERACTING_WITH_PUMP)
- {
- var _loc2_ = this.engine.labourPool.getKidAtFrontOfQueue();
- _loc2_.sendToNewPath(this.engine.goingToPump,Delegate.create(_loc2_,_loc2_.sendToNewQueue,this.queue));
- this.kidsInteractingWithPump = this.kidsInteractingWithPump + 1;
- }
- }
- }
- function update(f)
- {
- super.update();
- var _loc10_ = this.rotationSpeed;
- var _loc11_ = this._r;
- var _loc5_ = undefined;
- var _loc3_ = undefined;
- this.r = (this._r + this.rotationSpeed) % 1;
- if(this.queue.length)
- {
- if(this.queue[0].distAlongPath == this.queue.path.length)
- {
- var _loc7_ = 100;
- var _loc9_ = -1;
- var _loc4_ = undefined;
- _loc3_ = 0;
- while(_loc3_ < PlayPump.MAX_KIDS)
- {
- if(!this.slots[_loc3_])
- {
- _loc4_ = this.getPositionOfSlot(_loc3_);
- _loc4_ = Math.min(_loc4_,1 - _loc4_);
- if(_loc4_ < _loc7_)
- {
- _loc7_ = _loc4_;
- _loc9_ = _loc3_;
- }
- }
- _loc3_ = _loc3_ + 1;
- }
- if(_loc9_ >= 0)
- {
- this.slots[_loc9_] = true;
- _loc5_ = this.queue.getKidAtFrontOfQueue();
- _loc5_.joinPump(this,_loc9_);
- }
- }
- }
- var _loc8_ = undefined;
- _loc3_ = 0;
- while(_loc3_ < this.slots.length)
- {
- if((_loc5_ = this.slots[_loc3_]) instanceof Kid)
- {
- _loc8_ = this.getPositionOfSlot(_loc3_);
- f = Math.floor(_loc8_ * this.spinnerGuide.length) + 1;
- if(_loc5_.distAlongPath != f)
- {
- _loc5_.distAlongPath = f;
- _loc5_.mc.setPos(this.spinnerGuide.getPositionAtFrame(f,_loc5_.mc._parent));
- }
- }
- _loc3_ = _loc3_ + 1;
- }
- return _loc10_ * PlayPump.LITRES_PER_ROTATION;
- }
- function getSlotForKid(kid)
- {
- var _loc2_ = 0;
- while(_loc2_ < PlayPump.MAX_KIDS)
- {
- if(this.slots[_loc2_] == kid)
- {
- return _loc2_;
- }
- _loc2_ = _loc2_ + 1;
- }
- }
- function getPositionOfSlot(n)
- {
- return (this._r + (PlayPump.MAX_KIDS - n) * PlayPump.SLOT_ANG) % 1;
- }
- function leave(kid)
- {
- this.kidsInteractingWithPump = this.kidsInteractingWithPump - 1;
- delete this.slots[this.getSlotForKid(kid)];
- }
- function get numberOfKids()
- {
- var _loc3_ = 0;
- var _loc2_ = 0;
- while(_loc2_ < PlayPump.MAX_KIDS)
- {
- if(this.slots[_loc2_] instanceof Kid)
- {
- _loc3_ = _loc3_ + 1;
- }
- _loc2_ = _loc2_ + 1;
- }
- return _loc3_;
- }
- function get rotationSpeed()
- {
- var _loc5_ = undefined;
- var _loc3_ = 0;
- var _loc4_ = 0;
- var _loc2_ = 0;
- while(_loc2_ < this.slots.length)
- {
- if((_loc5_ = this.slots[_loc2_]) instanceof Kid)
- {
- _loc4_ = _loc4_ + 1;
- _loc3_ += _loc5_.pushForce;
- }
- _loc2_ = _loc2_ + 1;
- }
- if(_loc4_ > 0)
- {
- var _loc6_ = _loc3_ / _loc4_;
- _loc2_ = PlayPump.OPTIMUM_KIDS;
- while(_loc2_ < _loc4_)
- {
- _loc3_ -= _loc6_ * (_loc2_ / (PlayPump.MAX_KIDS / PlayPump.OPTIMUM_KIDS));
- _loc2_ = _loc2_ + 1;
- }
- _loc3_ = _loc3_ >= PlayPump.MIN_TURN_SPEED ? _loc3_ : PlayPump.MIN_TURN_SPEED;
- }
- return _loc3_ / 3 * PlayPump.OPTIMUM_SPEED * (1 / (Engine.FPS * 60));
- }
- function get effort()
- {
- return 1;
- }
- function get r()
- {
- return this._r;
- }
- function set r(n)
- {
- var _loc2_ = Math.floor(4 * n * (this.spinner._totalframes - 1) % (this.spinner._totalframes - 1)) + 1;
- this.spinner.gotoAndStop(_loc2_);
- this.shadow.gotoAndStop(_loc2_);
- this._r = n;
- }
- }
-